package top.goldenyear.porpoise.system.account.controller.admin;


import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import top.goldenyear.porpoise.common.core.model.Ret;
import top.goldenyear.porpoise.framework.web.core.controller.BaseController;
import top.goldenyear.porpoise.framework.web.core.model.query.QPage;
import top.goldenyear.porpoise.system.account.model.Account;
import top.goldenyear.porpoise.system.account.service.AccountService;

/**
 * 管理员账号表 Controller 控制层
 *
 * @author airhead
 * @since 2024-10-13
 */
@Component(tag = "adminApi")
@Mapping("/account")
@Slf4j
public class AccountAdminController extends BaseController {
  @Inject private AccountService service;

  @Post
  @Mapping("create")
  public Ret create(@Body Account account) {
    return service.createAccount(account);
  }

  @Post
  @Put
  @Mapping("update")
  public Ret update(@Body Account account) {
    return service.updateAccount(account);
  }

  @Get
  @Mapping("get")
  public Ret get(@Param Integer id) {
    return Ret.okWithData(service.getAccount(id));
  }

  @Post
  @Delete
  @Mapping("delete")
  public Ret delete(@Param Integer id) {
    return Ret.okWithData(service.deleteAccount(id));
  }

  @Get
  @Mapping("paginate")
  public Ret paginate(QPage qPage) {
    Account account = getBean(Account.class);
    return Ret.okWithData(service.paginateAccount(qPage, account));
  }

  @Get
  @Mapping("list")
  public Ret list() {
    Account account = getBean(Account.class);
    return Ret.okWithData(service.listAccount(account));
  }
}
